package biz.datalk.industrialland.common.component.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author tarofang@163.com
 * @date 2022-10-17
 */
public class RedisChangeReceiver extends MessageListenerAdapter {
    private static final Logger log = LoggerFactory.getLogger(RedisChangeReceiver.class);

    private RedisSerializer<String> datalkRedisKeyPrefixSerializer;

    private Jackson2JsonRedisSerializer<Object> getJackson2JsonRedisSerializer;

    public RedisChangeReceiver(RedisSerializer<String> datalkRedisKeyPrefixSerializer,Jackson2JsonRedisSerializer<Object> getJackson2JsonRedisSerializer){
        this.datalkRedisKeyPrefixSerializer = datalkRedisKeyPrefixSerializer;
        this.getJackson2JsonRedisSerializer = getJackson2JsonRedisSerializer;
    }


    @Override
    public void afterPropertiesSet() {
        setDefaultListenerMethod("receiveMessage");
        setStringSerializer(datalkRedisKeyPrefixSerializer);
        setSerializer(getJackson2JsonRedisSerializer);
        super.afterPropertiesSet();
    }

}
